package com.kuhyygy.activity;

import com.kuhyygy.R;

import android.app.ListActivity;
import android.content.Intent;
import android.database.DataSetObserver;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AbsListView;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

/**
 * ListAdapter的使用,类似把整个activity当成一个table来使用,方便展示数据
 * @author acer
 *
 */
public class ListViewActivity extends ListActivity {
	
	private static final String[] contries = new String[]{"广州", "深圳", "肇庆", "汕头", "persons"};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// String[] resCities = getResources().getStringArray(R.array.cities);
		setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, contries));
		ListView lv = getListView();
		lv.setTextFilterEnabled(true);
		lv.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				CharSequence text = ((TextView)arg1).getText();
				if (text.equals("persons")) {
					startActivity(new Intent(ListViewActivity.this, PersonListViewActivity.class));
				}
				Toast.makeText(ListViewActivity.this, ((TextView)arg1).getText(), Toast.LENGTH_SHORT).show();
			}
		});
	}

}
